<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>hello world</title>
    <script src="../assets/js/vue.js"></script>
    <script src="../assets/js/jquery-3.2.1.min.js"></script>
</head>
<body>
    <h1>hello world</h1>
    <hr/>
    <div id="app">
       
    </div>
    <p><button onclick="destroy()">卸载destroy</button></p>
    <p><button onclick="reload()">更新forceUpdate</button></p>
    <p><button onclick="tick()">更改nextTick</button></p>

    <script>
        var jspang = Vue.extend({
            template: `
                <div>
                    <p>{{message}}</p>
                    <p>{{num}}</p>
                    <p><button @click="add">add</button></p>
                </div>
                `,
            data: function(){
                return {
                    message: "hello I'm Jspang!",
                    num:1
                }
            },
            methods:{
                add(){
                    this.num++;
                }
            },
            beforeCreate:function(){
                console.log('1-beforeCreate 初始化之前');
            },
            created:function(){
                console.log('2-created 创建完成');
            },
            beforeMount:function(){
                console.log('3-beforeMount 挂载之前');
            },
            mounted:function(){
                console.log('4-mounted 挂载完成');
            },
            beforeUpdate:function(){
                console.log('5-beforeUpdate 数据更新前');
            },
            updated:function(){
                console.log('6-updated 被更新后');
            },
            activated:function(){
                console.log('7-activated');
            },
            deactivated:function(){
                console.log('8-deactivated');
            },
            beforeDestroy:function(){
                console.log('9-beforeDestroy 销毁之前');
            },
            destroyed:function(){
                console.log('10-destroyed 销毁之后')
            }
        });

        //使用$mount来挂载到dom上
        var vm = new jspang().$mount("#app");

        
        function destroy(){
            //销毁vue实例
            vm.$destroy();
        }

        //销毁之后vue实例不可用,但是调用$forceUpdate()方法时,生命周期中的updated还是会被调用
        function reload(){
            //更新
            vm.$forceUpdate();
        }

        function tick(){
            vm.message = '数据被更新了';
            //数据更新之后的回调
            vm.$nextTick(function(){
                console.log('数据被更改之后的通知');
            });
        }
    </script>

</body>
</html>